<template>
	<view class="uni-goods-nav">
		<!-- 底部占位 -->
		<view class="uni-tab__seat" />
		<view class="uni-tab__cart-box flex">
			<view class="flex uni-tab__cart-sub-box">
				<view
					v-for="(item, index) in options"
					:key="index"
					class="flex uni-tab__cart-button-left"
					@click="onClick(index, item)"
					style="position: relative;"
				>
					<view class="uni-tab__icon"><image class="image" :src="item.icon" mode="widthFix" /></view>
					<text class="uni-tab__text">{{ item.text }}</text>
					<text class="cart-num" v-if="index == 2 && cartNum!=0">{{cartNum}}</text>
				</view>
			</view>
			<view class="uni-flex row center" style="padding: 20upx;">
				<view
					class="uni-nav-one"
					v-for="(v, k) in buttonGroup"
					:key="k"
					:class="v.class"
					@click="buttonClick(k, v)"
					hover-class="hover-opacity"
				>
					{{ v.text }}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: "UniGoodsNav",
	data() {
		return {
			state: 1,
			cartNum:0,
			canBuy:0,
			options: [
				{
					icon:"/static/img/shoucang.png",
					text: "收藏"
				},
				{
					icon: "/static/img/kefu.png",
					text: "客服"
				},
				{
					icon: "/static/img/gouwuche.png",
					text: "购物车"
				}
			],
			buttonGroup: [
				{
					text: "加入购物车",
					color: "#fff",
					class:"one"
				},
				{
					text:"立即购买",
					color: "#fff",
					class:"two"
				}
			]
		};
	},
	watch: {
		item: {
			handler(n) {
				console.log(n)
				this.canBuy=n.goodsStatus;
				this.state=n.isCollect;
				this.options[0]={
					icon: this.state == 1 ? "/static/img/yishoucang.png" : "/static/img/shoucang.png",
					text: this.state == 1?"取消收藏":"收藏"
				}
				this.buttonGroup[1]={
					text: this.canBuy ==1 || this.canBuy ==2? "已售罄":"立即购买",
					color: "#fff",
					class:this.canBuy ==1 || this.canBuy ==2?"three":"two"
				}
			},
			immediate: true,
			deep: true
		}
	},
	props: {
		fill: {
			type: Boolean,
			default: false
		},
		item: Object
	},
	methods: {
		// setCollitem(state) {
		// 	this.state = state;
		// },
		// setCanBuy(state){
		// 	this.canBuy=state;
		// },
		async getUserCart() {
			if(!uni.getStorageSync('uid')) return;
			const res = await this.$request("goods/cart-counts", {uid: uni.getStorageSync("uid")});
			if (res.result == 0) {
				if (res.data && res.data.counts) {
					this.cartNum = res.data.counts;
				}
			}else{
				this.$util.msg(res.resultNote);
			}
		},
		onClick(index, item) {
			if (uni.report) {
				uni.report(item.text, item.text);
			}
			this.$emit("itemonClick", {
				index,
				content: item
			});
		},
		buttonClick(index, item) {
			if (uni.report) {
				uni.report(item.text, item.text);
			}
			this.$emit("buttonClick", {
				index,
				content: item
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.uni-flex {
	flex: 1;
}
.cart-num {
	position: absolute;
	top: 10upx;
	right: 20upx;
	width:28upx;
	height:28upx;
	background: #ff5050;
	border-radius: 50%;
	color: #FFFFFF;
	font-size:24upx;
	text-align: center;
	line-height:28upx;
}

.one {
	background: #fe5380;
	border-radius: 40upx 0px 0px 40upx;
}
.two {
	background: #cc1313;
	border-radius: 0px 40upx 40upx 0px;
}
.three {
	background: #bec3cf;
	border-radius: 0px 40upx 40upx 0px;
}
.flex {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: row;
}

.uni-goods-nav {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex: 1;
	flex-direction: row;
	position: fixed;
	bottom: 0;
	width: 100%;
	box-shadow: 0 0 20upx 0 rgba(0, 0, 0, 0.5);
	z-index: 99;
	padding-bottom:var(--status-bar-height);
	background: #ffffff;
}

.uni-tab__cart-box {
	flex: 1;
	height: 100rpx;
	background-color: #fff;
	z-index: 900;
}

.uni-tab__cart-sub-box {
	width: 50%;
}

.uni-tab__right {
	overflow: hidden;
}

.uni-tab__cart-button-left {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex: 1;
	position: relative;
	justify-content: center;
	align-items: center;
	flex-direction: column;
	position: relative;
}

.uni-tab__icon {
	width: 42upx;
	height: 42upx;
}

.image {
	width: 42upx;
	height: 42upx;
}

.uni-tab__text {
	margin-top: 3px;
	font-size: $uni-font-size-sm;
	color: #666;
}

.uni-tab__cart-button-right {
	/* #ifndef APP-NVUE */
	display: flex;
	flex-direction: column;
	/* #endif */
	flex: 1;
	justify-content: center;
	align-items: center;
}

.uni-tab__cart-button-right-text {
	font-size: $uni-font-size-base;
	color: #fff;
	width: 221upx;
	line-height: 100upx;
	border-radius: 38upx;
}

.uni-tab__cart-button-right:active {
	opacity: 0.7;
}

.uni-tab__dot-box {
	/* #ifndef APP-NVUE */
	display: flex;
	flex-direction: column;
	/* #endif */
	position: absolute;
	right: 12px;
	top: 4px;
	justify-content: center;
	align-items: center;
}

.uni-tab__dot {
	padding: 0 4px;
	line-height: 15px;
	color: #ffffff;
	text-align: center;
	font-size: 12px;
	background-color: #ff0000;
	border-radius: 15px;
}
.uni-tab__dots {
	padding: 0 4px;
	border-radius: 15px;
}
.uni-nav-one {
	width: 195upx;
	height: 80upx;
	text-align: center;
	line-height: 80upx;
	color: #ffffff;
	font-size: 26upx;
}
</style>
